package com.mzj.saas.mservice.sms.controller;

import com.mzj.saas.commons.ResultBean;
import com.mzj.saas.mservice.sms.service.SmsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

/**
 * 短信验证码
 *
 * @author shun
 * @createDate: 2021年3月19日 下午7:24:51
 * @version: 1.0
 */
@Controller
@RequestMapping("/sms")
public class SmsController {
    @Autowired
    private SmsService smsService;

    /**
     * 发送模板短信
     *
     * @param mobile
     * @param type
     * @param code
     * @return
     * @author shun
     * @date 2021年3月19日
     */
    @PostMapping(value = "/code/{mobile}/{type}")
    @ResponseBody
    public ResultBean<Object> code(@PathVariable String mobile, @PathVariable Integer type,
                                   @RequestParam(required = false) String code,
                                   @RequestParam(required = false) String captcha,
                                   @RequestParam(required = false) String uuid) {
        return smsService.sendTemplateCodeSms(mobile, type, code,captcha,uuid);
    }

    @PostMapping(value = "/code2/{mobile}/{templateId}")
    @ResponseBody
    public String code2(@PathVariable String mobile, @PathVariable String templateId) {
        return smsService.sendTemplateSms(mobile, templateId);
    }

    @PostMapping(value = "/datas")
    @ResponseBody
    public String sendTemplateSmsWithData(@RequestParam(value = "mobile") String mobile,
                                          @RequestParam(value = "templateId") String templateId,
                                          @RequestBody String[] datas) {
        return smsService.sendTemplateSmsWithData(mobile, templateId, datas);
    }

}
